home *** CD-ROM | disk | FTP | other *** search
- -----BEGIN PGP SIGNED MESSAGE-----
-
- >>>>> In article <3174c0dc.7652220@news.flex.com.au>,
- >>>>> Tony == "Tony L" <cobweb@flex.com.au> writes:
-
- Tony> I have come across two different ways that 2 different beginners
- Tony> books recommend that every program should start. Could someone
- Tony> please tell me which one is the "BEST" or proper way?
-
- Tony> #include <stdio.h>
- Tony> void main()
- Tony> {
- Tony> printf("Hello!\n");
- Tony> return 0;
- Tony> }
-
- This is definitely wrong, and your compiler should complain about
- this. You have said that the function doesn't return a value, then
- you try to return zero.
-
-
- Tony> Or, the same as above but not include "void":
-
- Tony> #include <stdio.h>
- Tony> main()
- Tony> {
- Tony> printf("Hello!\n");
- Tony> return 0;
- Tony> }
-
- In this case, the compiler assumes "int main()" which is consistent
- with the return, so no error there.
-
- The two portable declarations for main() are "int main()" and "int
- main(int, char**)"; make sure you do return an integer! Some
- environments may accept other forms (for example "void main()"), but I
- don't recommend this for portable code.
-
- More info is in the FAQ.
-
-
- Tony> As I am just really starting out in "C", I'd like to get off to
- Tony> the right way. :-)
-
- Then perhaps you should have posted in comp.lang.c ;-)
- ^L
-
- -----BEGIN PGP SIGNATURE-----
- Version: 2.6.3i
- Charset: noconv
- Comment: Processed by Mailcrypt 3.4, an Emacs/PGP interface
-
- iQB1AwUBMXUA3edsuUurvcRtAQEyWQL/fsHHEh8nHWnXCvBocohn3xdn9ax8ClMl
- xi75oqFFU077b679KU1CmYp5EYZgXbi03jgDuzPQO88fxoTZo1AIZumpND58fY5U
- hF3nxAJIxZq2bQZ3B4Bw8sp8AWJqzb9i
- =4MPP
- -----END PGP SIGNATURE-----
-